home *** CD-ROM | disk | FTP | other *** search
/ Nikkei Mac 11 / NIKKEI-MAC-CD-VOL-11-1998-03.ISO.7z / NIKKEI-MAC-CD-VOL-11-1998-03.ISO / オンラインソフト / 2.日経MAC超定番 / UltraFind 2.5.3 Full Pack.sit / UltraFind 2.5.3 Full Package / AppleScript™ Examples / UF Find Text < prev    next >
Text File  |  1997-06-21  |  4KB  |  86 lines

  1.  
  2.     set numFiles to 0
  3.     tell application "UltraFind 2.5.3"
  4.         clear
  5.         
  6.         set the text of fileName of its searchRoutine to "read me"
  7.         set the searchType of fileName of its searchRoutine to nameIs
  8.         
  9.         set the text of targetWord 1 of searchText of its searchRoutine to "apple"
  10.         set the text of targetWord 2 of searchText of its searchRoutine to "version"
  11.         set the text of targetWord 3 of searchText of its searchRoutine to "project"
  12.         
  13.         --the following scripts are commented out and are included only as examples:
  14.         
  15.         -- example of how to use UltraFind's Thesaurus:
  16.         --    set the XRef of targetWord 1 of searchText of its searchRoutine to XRefON
  17.         
  18.         -- use this to find only those files which contain both target words:
  19.         --    set options of searchText of its searchRoutine to matchAll
  20.         
  21.         -- use this only if you want to search ALL types of files (including graphics images, application, etc.
  22.         -- without this only documents likely to contain text will be searched:
  23.         --    set options of searchText of its searchRoutine to searchAll
  24.         
  25.         -- use this only if you want to search the files' resource forks:
  26.         --    set options of searchText of its searchRoutine to searchResources
  27.         
  28.         -- you may want to search only those files in a specific directory, e.g.:
  29.         --    set the confineDirectory of its searchRoutine to "Hard Disk:Text Files"
  30.         
  31.         --set the maximum number of found words to show, e.g. 3
  32.         set showWords of searchText of its searchRoutine to 1
  33.         
  34.         scan
  35.         changeView finderView --make sure the list window is in FINDER VIEW to process the text found
  36.         copy the result to numFiles
  37.     end tell
  38.     
  39.     if numFiles is greater than 0 then
  40.         
  41.         --process the list in TEXT VIEW to get individual words and offsets
  42.         tell application "UltraFind 2.5.3" to changeView textView
  43.         copy the result to numRecords
  44.         set recNum to 1
  45.         set fileNum to 1
  46.         set dialogtext to ""
  47.         repeat until recNum is greater than numRecords
  48.             
  49.             tell application "UltraFind 2.5.3"
  50.                 copy (the fileName of fileRecord recNum) to fName
  51.                 copy (the textFound of fileRecord recNum) to fText
  52.                 copy (the textOffset of fileRecord recNum) to fOffset
  53.             end tell
  54.             set recNum to recNum + 1
  55.             
  56.             --in TEXT view each file found has one MASTER record and one or more TEXT records
  57.             --the MASTER record returns a list of all the words found but has no textoffset
  58.             --the TEXT record returns the words found and its location (textoffset) in characters from the start of the file
  59.             if fOffset is equal to "" then --its a master record
  60.                 --check if previous file's results dialog needs to be displayed
  61.                 if dialogtext is not equal to "" then
  62.                     set dialogtext to dialogtext & return
  63.                     display dialog dialogtext buttons {"Cancel", "Next"} default button 2
  64.                 end if
  65.                 set dialogtext to "Found file " & (fileNum as text) & " of " & (numFiles as text) & return & return & ツ
  66.                     "Text Search Results for File '" & fName & "' :" & return & return
  67.                 set fileNum to fileNum + 1
  68.             else
  69.                 set dialogtext to dialogtext & "At offset " & fOffset & " found '" & fText & "'" & return
  70.             end if
  71.         end repeat
  72.         
  73.         --repeat with fileNum from 1 to numFiles
  74.         --    tell application "UltraFind"
  75.         --        copy (the fileName of fileRecord fileNum) to fName
  76.         --        copy (the textFound of fileRecord fileNum) to fText
  77.         --    end tell
  78.         
  79.         --    display dialog "Found file " & (fileNum as text) & " of " & (numFiles as text) & return & return & ツ
  80.         --        "Filename : " & fName & return & ツ
  81.         --        "Found words: '" & fText & "'" & return & return ツ
  82.         --        buttons {"Cancel", "Next"} default button 2
  83.         --end repeat
  84.         
  85.     end if
  86. end if